<template>
  <div class="packages">
    <div ref="refsTable">
      <el-form style="margin-top: 10px" label-width="68px" :inline="true">
        <el-form-item label="登记时间">
          <el-date-picker v-model="value1" type="datetimerange" start-placeholder="开始日期" end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange1" style="width:380px" :default-time="['00:00:00', '23:59:59']" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="分析时间">
          <el-date-picker v-model="value2" type="datetimerange" start-placeholder="开始日期" end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange2" style="width:380px" :default-time="['00:00:00', '23:59:59']" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="项目类型">
          <el-autocomplete
            class="inline-input"
            v-model="params.projectTypeName"
            :fetch-suggestions="querySearch"
            placeholder="请选择"
            @select="handleSelectProject"
            @focus="change(1)"
            style="width:228px"
            clearable
          ></el-autocomplete>
          <!-- <el-select v-model="params.projectType" placeholder="请选择" style="width:228px">
            <el-option value label="全部"></el-option>
            <el-option v-for="item in Arr.projectTypeArr" :key="item.id" :label="item.name"
              :value="item.id"></el-option>
          </el-select> -->
        </el-form-item>

        <el-form-item label="样本类型">
          <el-autocomplete
            class="inline-input"
            v-model="params.sampleTypeName"
            :fetch-suggestions="querySearch"
            placeholder="请选择"
            @select="handleSelectSample"
            @focus="change(0)"
            style="width:228px"
            clearable
          ></el-autocomplete>
          <!-- <el-select v-model="params.sampleType" placeholder="请选择" style="width:228px">
            <el-option value label="全部"></el-option>
            <el-option v-for="item in Arr.sampleTypeArr" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select> -->
        </el-form-item>

        <el-form-item label="核酸类型">
          <el-select v-model="params.nucleicAcidType" placeholder="请选择" style="width:228px">
            <el-option value label="全部"></el-option>
            <el-option v-for="item in Arr.nucleicAcidTypeArr" :key="item.id" :label="item.typeName"
              :value="item.id"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="平台类型">
          <el-select v-model="params.platformType" placeholder="请选择" style="width:228px">
            <el-option value label="全部"></el-option>
            <el-option v-for="item in Arr.platformTypeArr" :key="item.id" :label="item.platformType"
              :value="item.id"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="条码号">
          <!-- <el-autocomplete class="inline-input" v-model="params.barcodeCode" :fetch-suggestions="querySearch"
            placeholder="请输入条码号" @select="handleSelect" @focus="change(0)" style="width:228px"></el-autocomplete> -->
            <el-input clearable v-model="params.barcodeCode" style="width:228px" placeholder="请输入条码号"></el-input>
        </el-form-item>

        <el-form-item label="实验编号">
          <!-- <el-autocomplete class="inline-input" v-model="params.barcode" :fetch-suggestions="querySearch"
            placeholder="实验编号或流水号" @select="handleSelect" @focus="change(0)" style="width:228px"></el-autocomplete> -->
            <el-input clearable v-model="params.experimentNumber" style="width:228px" placeholder="实验编号或流水号"></el-input>
        </el-form-item>

        <el-form-item label="分析状态">
          <el-select v-model="params.analyzeState" placeholder="请选择" style="width:228px">
            <el-option value label="全部"></el-option>
            <el-option v-for="item in arr.analyzeStateArr" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="关键字">
          <!-- <el-autocomplete class="inline-input" v-model="params.keyword" :fetch-suggestions="querySearch"
            placeholder="请输入关键字" @select="handleSelect" @focus="change(1)" style="width:228px"></el-autocomplete> -->
            <el-input clearable v-model="params.keyword" style="width:228px" placeholder="送检单位/姓名/分析批次号"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button size="mini" icon="el-icon-search" type="primary" @click="getList">查询</el-button>
          <el-button size="mini" icon="el-icon-refresh" @click="reset">重置</el-button>
        </el-form-item>


      </el-form>
      <el-form :inline="true">
        <el-form-item>
          <el-button size="mini" type="primary" @click="analysis">分析</el-button>
        </el-form-item>
        <el-form-item style="margin-left: 10px">
          <el-button size="mini" type="primary" @click="returnAnalysis">重新分析</el-button>
        </el-form-item>
        <el-form-item style="margin-left: 10px">
          <el-button size="mini" type="primary" @click="cancelAnalysis">取消分析</el-button>
        </el-form-item>

        <el-form-item style="margin-left: 10px;float:right">
          <el-dropdown trigger="click" placement="bottom" @command="handleCommand">
            <el-button size="mini" type="primary">
              导出
              <i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="20">导出当前</el-dropdown-item>
              <el-dropdown-item command="99999">导出全部</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-form-item>
        <el-form-item style="margin-left: 10px;float:right">
          <el-button size="mini" type="primary" @click="computerConfig">上机配置</el-button>
        </el-form-item>
        <el-form-item style="margin-left: 10px;float:right">
          <el-button size="mini" type="primary" @click="analysisReturn">回退</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%" border
      @selection-change="handleSelectionChange" :header-cell-style="{background: '#ebebeb'}" highlight-current-row :row-class-name="rowStyle" :height="heights" v-loading="loading" :cell-style="cellStyle">
      <el-table-column align="center" type="selection" width="55"></el-table-column>
      <el-table-column align="center" type="index" width="50" label="序号"></el-table-column>
      <el-table-column align="center" label="条码号" prop="barcodeCode" width="120"></el-table-column>
      <el-table-column align="center" prop="projectTypeName" label="项目类型" width="380"></el-table-column>
      <el-table-column align="center" prop="experimentNumber" label="实验编号" width="200"></el-table-column>
      <el-table-column align="center" prop="sampleState" label="样本状态" width="100">
        <template slot-scope="{row}">{{ row.sampleState == 1 ? '已分析' : '已测序' }}</template>
        <!-- <template slot-scope="{row}">{{ arr.mainStateObj[row.mainState] }}</template> -->
      </el-table-column>
      <el-table-column align="center" prop="analyzeState" label="分析状态">
        <template slot-scope="{row}">
          <span v-if="row.analyzeState == 0">待分析</span>
          <span v-if="row.analyzeState == 1">分析中</span>
          <span v-if="row.analyzeState == 2">分析失败</span>
          <span v-if="row.analyzeState == 3">分析成功</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="分析耗时" prop="analyzeTimeConsuming">
        <template slot-scope="{row}">
          {{Math.trunc(row.analyzeTimeConsuming/3600)}}小时
        </template>
      </el-table-column>
      <el-table-column align="center" prop="analyzeSampleNumber" label="分析样本编号" width="250"></el-table-column>
      <el-table-column align="center" prop="analyzeBatchNumber" label="分析批次号" width="150"></el-table-column>
      <el-table-column align="center" prop="analyzeNumber" label="分析序号"></el-table-column>
      <el-table-column align="center" prop="registrationTime" label="登记时间" show-overflow-tooltip width='160'></el-table-column>
      <el-table-column align="center" prop="otherSampleTypes" label="其他样本类型" width="150"></el-table-column>
      <el-table-column align="center" prop="analyzePerson" label="分析人"></el-table-column>
      <el-table-column align="center" prop="analyzeDate" label="分析日期" show-overflow-tooltip width='160'></el-table-column>
      <el-table-column align="center" prop="submitName" label="送检姓名"></el-table-column>
      <el-table-column align="center" prop="inspectionUnit" label="送检单位" width="200"
        show-overflow-tooltip></el-table-column>
      <el-table-column align="center" prop="projectTypeName" label="平台类型" width="380"></el-table-column>
      <el-table-column align="center" prop="nucleicAcidName" label="核酸类型" width="100"></el-table-column>
      <el-table-column align="center" prop="sampleTypeName" label="样本类型" width="150" show-overflow-tooltip></el-table-column>
      <el-table-column align="center" prop="isVoid" label="是否作废">
        <template slot-scope="{row}">{{ row.isVoid == 1 ? '是' : '否' }}</template>
      </el-table-column>
      <el-table-column align="center" prop="reasonName" label="作废原因" width="100"
        show-overflow-tooltip></el-table-column>
      <el-table-column align="center" prop="remark" label="备注" width="100" show-overflow-tooltip></el-table-column>

      <el-table-column align="center" label="操作" width="190" fixed="right">
        <template slot-scope="scope">
          <div class="czDiv" style="font-size:14px">
            <span style="color:#0186ef;cursor:pointer" @click="stop(scope.row.id,)">终止</span>
            <span style="color:#0186ef;cursor:pointer" @click="openAnalysisDialog(scope.row.analyzeResult)">分析结果信息</span>
            <span v-show="scope.row.isVoid == 0" style="color:#0186ef;cursor:pointer"
              @click="nullify(scope.row.id, scope.row.stateId,scope.row)">作废</span>
            <span v-show="scope.row.isVoid == 1" style="color:#0186ef;cursor:pointer"
              @click="toEnabled(scope.row.id,scope.row)">启用</span>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <div class="block">
      <div>
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :page-sizes="[20, 50, 100, 200, 500]" layout="total, sizes, prev, pager, next, jumper" :total="listTotal"
          background></el-pagination>
      </div>
    </div>

    <el-dialog :visible.sync="nullifyDialog" style="margin-top:15vh;" title="提示" width="500px">
      <el-form :model="ruleForm2" :rules="rules2" class="demo-ruleForm" ref="ruleForm2" :inline="true">
        <el-form-item label="请输入作废原因" prop="dictReasonId">
          <el-select v-model="ruleForm2.dictReasonId" placeholder="请选择" style="width:320px">
            <el-option v-for="item in Arr.reasonNameArr" :key="item.id" :label="item.reasonName"
              :value="item.id"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="nullifyDialog = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="sureToNullify('ruleForm2')">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog :visible.sync="configDialog" style="margin-top:15vh;" title="上机配置" width="500px">
      <el-input clearable type="textarea" :rows="12" placeholder="请输入内容" v-model="resultFile"></el-input>

      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="configDialog = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="sureToConfig">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog :visible.sync="analysisDialog" style="margin-top:15vh;" title="分析结果" width="500px">
      <el-input clearable type="textarea" :rows="12" v-model="analyzeResult" disabled></el-input>

      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="analysisDialog = false">关闭</el-button>
      </span>
    </el-dialog>
    <!-- 回退 -->
    <el-dialog :visible.sync="returnDialog" width="750px" title="回退申请" class="returnForm">
      <el-form :model="returnData" :rules="rules3" ref="ruleForm3" label-width="110px" class="demo-ruleForm"
        :inline="true">
        <el-form-item label="条码号">
          <el-input clearable style="width:210px" v-model="returnData.barcodeCode" disabled></el-input>
        </el-form-item>
        <el-form-item label="项目类型">
          <el-input clearable style="width:210px" v-model="returnData.projectTypeName" disabled></el-input>
        </el-form-item>
        <el-form-item label="实验编号">
          <el-input clearable style="width:210px" v-model="returnData.experimentNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="样本状态">
          <!-- <el-input clearable style="width:210px" v-model="arr.analyzeStateObj[returnData.analyzeState]" disabled></el-input> -->
          <el-input clearable style="width:210px" v-model="arr.mainStateObj[returnData.mainState]" disabled></el-input>
        </el-form-item>
        <el-form-item label="提取样本编号">
          <el-input clearable style="width:210px" v-model="returnData.analyzeSampleNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="提取批次号">
          <el-input clearable style="width:210px" v-model="returnData.analyzeBatchNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="核酸类型">
          <el-input clearable style="width:210px" v-model="returnData.nucleicAcidName" disabled></el-input>
        </el-form-item>
        <el-form-item label="样本类型">
          <el-input clearable style="width:210px" v-model="returnData.sampleTypeName" disabled></el-input>
        </el-form-item>
        <el-form-item label="送检姓名">
          <el-input clearable style="width:210px" v-model="returnData.submitName" disabled></el-input>
        </el-form-item>
        <el-form-item label="送检单位">
          <el-input clearable style="width:210px" v-model="returnData.inspectionUnit" disabled></el-input>
        </el-form-item>
        <el-form-item label="回退环节" prop="flowBackState">
          <el-radio-group v-model="returnData.flowBackState">
            <el-radio :label="2">入库</el-radio>
            <el-radio :label="3">提取</el-radio>
            <el-radio :label="4">建库</el-radio>
            <el-radio :label="5">测序</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="回退原因" prop="fallbackReason">
          <!-- <el-select v-model="returnData.fallbackReason" placeholder="请选择" style="width:210px">
          <el-option v-for="item in backReasonList" :key="item.id" :label="item.backReason" :value="item.backReason">
          </el-option>
        </el-select> -->
          <el-input clearable v-model="returnData.fallbackReason" placeholder="请输入回退原因" style="width:210px"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="resetRegister('ruleForm3')">取消</el-button>
        <el-button size="mini" type="primary" @click="submitRegister3('ruleForm3')">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
        
<script>
import {
  exportAnalysis,
  analysisList,
  analysisEnabled,
  analyzeToVoid,
  goAnalysis,
  reAnalysis,
  stopAnalysis,
  returnApply,
  saveHost,
  cancelAnalysis
} from "@/api/technologyManage/index.js";
import { manageBackList, manageBackAdd,manageOperation } from '@/api/comprehensiveSearchManage/fallback.js'
import { voidPlaceOn,delPlaceOn } from '@/api/commonArr/index.js'
import { arr, Arr } from "@/utils/data.js";
export default {
  data() {
    return {
      pickerOptions: {
        disabledDate(time){
          return time.getTime()>Date.now()
        },
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      backReasonList: [],
      loading: false,
      value1: [],
      value2: [],
      multipleSelection: [],
      restaurants: [],
      tableData: [],
      rules: {
        name: [{ required: true, Message: "请输入名称", trigger: "blur" }]
      },
      ruleForm: {},
      nullifyDialog: false,
      configDialog: false,
      resultFile: "",
      analysisDialog: false,
      textarea2: "",
      sampleTypeList:[],
      params: {
        pageNum: 1,
        pageSize: 20,
        projectType: "",
        sampleType: "",
        nucleicAcidType: "",
        platformType: "",
        experimentalStatus: "",
        analyzeState: "",
        qualityControlStatus: ""
      },
      listTotal: 0,
      arr: {},
      Arr: {},
      ids: [],
      returnDialog: false,
      returnData: {},
      rules3: {
        fallbackReason: [
          { required: true, message: "请输入回退原因", trigger: "blur" }
        ],
        flowBackState: [
          { required: true, message: "请选择回退环节", trigger: "change" }
        ]
      },
      rules2: {
        dictReasonId: [
          { required: true, message: "请输入作废原因", trigger: "change" }
        ]
      },
      ruleForm2: {},
      row:{},
      id: "",
      heights: undefined,
      stateId: '',
      analyzeResult:'',
      returnStateObj:{
        0:40,
        1:50,
        2:70,
        3:60
      },
      projectTypeList:[],
      isSame:false
    };
  },
  created() { },
  methods: {
    voidPlaceOn() {
      voidPlaceOn({ stateId: this.stateId, status: 0 }).then(() => {
      })
    },
    // 下拉框
    querySearch(queryString, cb) {
      var restaurants = this.restaurants;
      var results = queryString
        ? restaurants.filter(this.createFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    createFilter(queryString) {
      return restaurant => {
        return (
          restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
          0
        );
      };
    },
    // 多个下拉框的数据
    loadAll() {
      const array = [
        this.sampleTypeList,
        this.projectTypeList,
        
      ];
      return array;
    },
    handleSelect(item) {
      console.log(item);
    },
    // 聚焦下拉框时
    change(i) {
      this.restaurants = this.loadAll()[i];
      // console.log(this.restaurants);
    },
    // 表格复选框
    handleSelectionChange(val) {
      this.multipleSelection = val;
      this.ids = val.map(item => item.id);
    },
    cellStyle({row, column, rowIndex, columnIndex}){
        if(columnIndex === 7){ //指定坐标rowIndex ：行，columnIndex ：列
          if (row.analyzeTimeConsuming/3600<=2) {
            return 'background:rgb(149 242 4)'
          }else if (row.analyzeTimeConsuming/3600<=3) {
            return 'background:orange'
          }else if (row.analyzeTimeConsuming/3600>3) {
            return 'background:red'
          }else if (row.analyzeTimeConsuming/3600===0||row.analyzeTimeConsuming/3600==null) {
            return ''
          }
    }else{
        return ''
    }},

    returnAnalysis() {
      if (
        this.multipleSelection.length === 0 ||
        this.multipleSelection.length > 1
      ) {
        this.$message.error("至多选择一项");
        return;
      }
      this.id = this.multipleSelection[0].id;
      this.$confirm("是否重新分析?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        reAnalysis(this.id).then(() => {
          this.$message({
            type: "success",
            message: "重新分析成功!"
          });
          this.getList();
        })

      });
    },
    // 作废
    nullify(id, stateId,row) {
      this.row=row
      this.nullifyDialog = true;
      this.id = id;
      this.stateId = stateId
    },
    // 确认作废
    sureToNullify(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          analyzeToVoid({
            dictReasonId: this.ruleForm2.dictReasonId,
            id: this.id
          }).then(() => {
            this.$message.success("已作废");
            this.nullifyDialog = false;
            this.getList();
            this.voidPlaceOn()
            this.row.status=0
        this.row.operationStatus=0
        manageOperation(this.row)
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    toEnabled(id,row) {
      this.$confirm("是否确认启用?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        analysisEnabled({ id }).then(() => {
          this.$message.success("启用成功");
          this.getList();
          delPlaceOn(row.stateId)
        });
      });
    },
    stop(id) {
      this.$confirm("是否终止该上机数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        stopAnalysis(id).then(() => {
          this.$message({
            type: "success",
            message: "终止成功!"
          });
          this.getList();
        })

      });
    },

    analysis() {
      if (
        this.multipleSelection.length === 0
      ) {
        this.$message.error("请勾选内容");
        return;
      }
      if (this.multipleSelection.some(item => {
        return item.isCompare === 0
      })) {
        this.$message.error('请先进行登记对照')
        return
      }     
      this.multipleSelection.map((el,i)=>{
        console.log(this.multipleSelection[i].barcodeCode);
        for(let j=i+1;j<this.multipleSelection.length;j++){        
          console.log(this.multipleSelection[j].barcodeCode);
          if(String(this.multipleSelection[i].barcodeCode)===String(this.multipleSelection[j].barcodeCode)){
            this.isSame=true
          }else{
            this.isSame=false
          }
        }
      })
      console.log(this.isSame);
      if(this.isSame){
        this.$message.error("不能分析相同的数据");
        return;
      }
      let idList=[]
      this.multipleSelection.map(el=>{
        idList.push(el.id)
      })
      // return
      this.$confirm("是否分析?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        goAnalysis(idList).then(() => {
          this.$message({
            type: "success",
            message: "分析成功!"
          });
          this.getList();
        });
      });
    },
    cancelAnalysis() {
      if (
        this.multipleSelection.length === 0         
      ) {
        this.$message.error("请勾选内容");
        return;
      }
      this.$confirm("是否取消分析?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let idList=[]
      this.multipleSelection.map(el=>{
        idList.push(el.id)
      })
        // let id = this.multipleSelection[0].id
        cancelAnalysis(idList).then(() => {
          this.$message({
            type: "success",
            message: "取消分析成功!"
          })
          this.getList();
        })
      });
    },
    openAnalysisDialog(res){
      this.analysisDialog = true
      this.analyzeResult=res
    },
    computerConfig() {
      if(this.multipleSelection.length===0){
        this.$message.error('请勾选内容')
        return
      }
      this.configDialog = true;
    },
    sureToConfig() {
      let stateIds=[]
      this.multipleSelection.map(el=>{
        stateIds.push(el.stateId)
      })
      let data={
        resultFile:this.resultFile,
        stateIds
      }
      saveHost(data).then(()=>{
        this.$message.success('上机配置成功')
        this.configDialog = false;
        this.getList()
      })
   
    },
    handleExport() {
      const queryParams = this.params;
      this.$confirm("是否确认导出数据?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function () {
          return exportAnalysis(queryParams);
        })
        .then(response => {
          this.download(response.msg);
        });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.params.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.params.pageNum = val;
      this.getList();
    },
    getList() {
      this.loading = true
      analysisList(this.params).then(res => {
        this.tableData = res.rows;
        this.listTotal = res.total;
        this.loading = false
      });
    },
    timeChange1() {
      if (!this.value1) {
        this.value1 = []
      }
      this.params.registrationStartTime = this.value1[0];
      this.params.registrationEndTime = this.value1[1];
    
    },
    timeChange2() {
      if (!this.value2) {
        this.value2 = []
      }
      this.params.analyzeStartDate = this.value2[0];
      this.params.analyzeEndDate = this.value2[1];
    },
    reset() {
      this.params = {
        pageSize: 20,
        pageNum: 1,
        projectType: "",
        sampleType: "",
        nucleicAcidType: "",
        platformType: "",
        experimentalStatus: "",
        analyzeState: "",
        qualityControlStatus: ""
      };
      this.value1 = []
      this.value2 = []
      this.getList();
    },
    rowStyle({ row }) {
      var arr = this.ids;
      for (let i = 0; i < arr.length; i++) {
        if (row.id === arr[i]) {
          return "rowStyle";
        }
      }
    },
    analysisReturn() {
      if (this.multipleSelection.length == 0) {
        this.$message.error("请勾选内容");
        return;
      }
      if (this.multipleSelection.lenght > 1) {
        this.$message.error("至多选一项");
        return;
      }
      this.returnDialog = true;
      this.returnData = this.multipleSelection[0];
      manageBackList({ pageNum: 1, pageSize: 999 }).then(res => {
        this.backReasonList = res.rows
      })
    },
    resetRegister(formName) {
      this.$refs[formName].resetFields(); //清空
      this.dialogVisible = false;
      this.returnDialog = false;
    },
    submitRegister3(formName) {
      const data = {
        fallbackReason: this.returnData.fallbackReason,
        flowBackState: this.returnData.flowBackState,
        stateId: this.returnData.stateId
      };
      this.$refs[formName].validate(valid => {
        if (valid) {
          returnApply(data).then(() => {
            this.$message.success("回退成功");
            this.returnDialog = false;
            this.getList();
            this.multipleSelection[0].backReason = this.returnData.fallbackReason
            // this.multipleSelection[0].status = this.returnData.flowBackState
            this.multipleSelection[0].status=this.returnStateObj[this.multipleSelection[0].analyzeState]
            this.multipleSelection[0].projectTypeId = this.multipleSelection[0].projectType
            this.multipleSelection[0].nucleicAcidTypeId = this.multipleSelection[0].nucleicAcidType
            this.multipleSelection[0].platformTypeId = this.multipleSelection[0].platformType
            this.multipleSelection[0].sampleTypeId = this.multipleSelection[0].sampleType
            this.multipleSelection[0].nucleicAcidTypeName = this.multipleSelection[0].nucleicAcidName
            manageBackAdd(this.multipleSelection[0])
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    handleCommand(command) {
      this.params.pageSize = command;
      this.handleExport();
    },
    getDefaultDate() {
      var now = new Date();
      var date = now.getDate();
      // now.setDate(date - 1);  //获取前一天
      var y = now.getFullYear();
      var m = (now.getMonth() + 1).toString().padStart(2, "0");
      var d = now.getDate().toString().padStart(2, "0");
      var defaultDate = y + "-" + m + "-" + d + ' ' + '00:00:00';

      var defaultDate2 = y + "-" + m + "-" + d + ' ' + '23:59:59';
      this.$set(this.value1, 0, defaultDate),
        this.$set(this.value1, 1, defaultDate2)
      // this.$set(this.value2, 0, defaultDate),
      //   this.$set(this.value2, 1, defaultDate2)
      this.timeChange1()
      // this.timeChange2()
    },
    handleSelectSample(item) {
      this.params.sampleType=item.id
    },
    handleSelectProject(item){
      this.params.projectType=item.id
    },
  },
  created() {
    this.getDefaultDate();
    Arr.sampleTypeArr.map(el=>{
      this.sampleTypeList.push({
        value:el.name,
        id:el.id
      })
    })
    Arr.projectTypeArr.map(el=>{
      this.projectTypeList.push({
        value:el.name,
        id:el.id
      })
    }) 
  },
  mounted() {
    this.getList();
    this.arr = arr;
    this.Arr = Arr;
    // this.Arr.sampleTypeArr.map(el=>{
    //   this.sampleTypeList.push({
    //     value:el.name
    //   })
    // })
    this.$nextTick(() => {
      // 根据浏览器高度设置初始高度
      this.heights =
        window.innerHeight - this.$refs.refsTable.offsetHeight - 150;
      // 监听浏览器高度变化，修改表格高度
      window.onresize = () => {
        this.heights =
          window.innerHeight - this.$refs.refsTable.offsetHeight - 150;
      };
    });
  },
  updated() {
    this.$refs["multipleTable"].doLayout();
  }
};
</script>
        
<style lang="scss" scoped>
.packages {
  padding-left: 10px;

  // position: relative;
  .czDiv {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: space-evenly;
  }

  .importButton {
    width: 100%;
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
  }

  .block {
    width: 100%;
    // height: 50px;
    background-color: #fff;
    position: absolute;
    display: flex;
    flex-direction: row-reverse;
    bottom: 10px;
    right: 20px;
    z-index: 99;
  }

  .el-col-5 {
    width: 20%;
  }

  .el-autocomplete {
    width: 216px;
  }

  ::v-deep .el-table__body tr.current-row>td {
    background: #a8d6fe !important;
  }

  ::v-deep .el-table__body tr:hover>td {
    background: #a8d6fe !important;
  }

  ::v-deep .rowStyle {
    background-color: #a8d6fe !important;
  }

  .el-row {
    display: flex;
    flex-wrap: wrap;
  }

  .el-form-item {
    margin-bottom: 10px;
  }

  .returnForm {
    .el-form-item {
      margin-bottom: 17px;
    }
  }

  .topDiv {

    ::v-deep .el-form-item__label {
      font-size: 12px;
      padding: 0 5px 0 0;
      margin: 0;

    }

  }
}
</style>